<?php

namespace App\Console\Commands\Check;

use App\Enums\Check\CheckEnum;
use App\Enums\Pay\RmsPayEnum;
use App\Service\Check\CheckStreamParam;
use App\Service\Check\CheckStreamService;
use Illuminate\Console\Command;

class CreateCheckStream extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'check:create-check-stream {date?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '创建某天的对账信息';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $date = $this->input->getArgument('date');
        if (!$date) {
            $date = date('Ymd', time() - 86400);
        }

        $sysTypes = CheckEnum::CHECK_SYS_TYPES;
        $startTime = strtotime($date);
        $endTime   = $startTime + 86400 - 1;

        // TODO 测试用
//        $startTime = 1647705600;
//        $endTime = time();

        $param = (new CheckStreamParam())->setSysTypes($sysTypes)->setStartTime($startTime)->setEndTime($endTime);

        (new CheckStreamService($param))->doCheck();

        $this->info('success');
    }
}
